package com.situ.car.service.Impl;

import com.situ.car.dao.ICarDao;
import com.situ.car.dao.IOrderDao;
import com.situ.car.dao.IReturnDao;
import com.situ.car.dao.Impl.CarDaoImpl;
import com.situ.car.dao.Impl.OrdorDaoImpl;
import com.situ.car.dao.Impl.ReturnDaoImpl;
import com.situ.car.pojo.entity.Car;
import com.situ.car.pojo.query.CarQuery;
import com.situ.car.pojo.vo.CarVo;
import com.situ.car.service.ICarService;
import com.situ.car.util.PageInfo;

import java.util.List;

public class CarServiceImpl implements ICarService {
    private ICarDao carDao = new CarDaoImpl();
    private IReturnDao returnDao = new ReturnDaoImpl();
    private IOrderDao orderDao = new OrdorDaoImpl();
    @Override
    public PageInfo selectByPage(CarQuery carQuery) {
        List<CarVo> list = carDao.selectByPage(carQuery);
        int totalCount = carDao.selectTotalCount(carQuery);
        return PageInfo.ok(totalCount, list);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        carDao.updateStatus(id, status);
    }

    @Override
    public void add(Car car) {
        carDao.add(car);
    }

    @Override
    public void deleteById(Integer id) {
        returnDao.deleteByCarId(id);
        orderDao.deleteByCarId(id);
        carDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            returnDao.deleteByCarId(Integer.parseInt(id));
            orderDao.deleteByCarId(Integer.parseInt(id));
            carDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public Car selectById(Integer id) {
        return carDao.selectById(id);
    }

    @Override
    public Integer update(Car car) {
        return carDao.update(car);
    }

    @Override
    public List<Car> selectOrder() {
        return carDao.selectOrder();
    }

    @Override
    public void updateRentalStatus(Integer carId) {
        carDao.updateRentalStatus(carId);
    }

    @Override
    public void updateRentalStatusUp(String licensePlate) {
        carDao.updateRentalStatusUp(licensePlate);
    }

    @Override
    public void updateCarStatus(Integer rentalId) {
        carDao.updateCarStatus(rentalId);
    }

    @Override
    public Integer totalCost() {
        return carDao.totalCost();
    }

    @Override
    public Integer selectLicensePlateCount(Car car) {
        return carDao.selectLicensePlateCount(car);
    }
}
